﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI_Test
{
    public partial class SubFormOracleConnection : Form
    {
        public SubFormOracleConnection()
        {
            InitializeComponent();

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!validateUserInput())
            {
                //return;
            }

        }


        private bool validateUserInput()
        {
            if (textBoxOracleServerName.Text.Trim() == string.Empty || textBoxOracleDBName.Text.Trim() == string.Empty
                || textBoxOracleServiceId.Text.Trim() == string.Empty || textBoxOracleUserId.Text.Trim() == string.Empty
                || textBoxOraclePassword.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please fill all required fields.", "Error: Invalid Entry");
                return false;
            }
            int result;
            if (!int.TryParse(textBoxOracleDBName.Text.Trim(), out result))
            {
                MessageBox.Show("Please enter a valid port number.", "Error: Invalid Entry");
                return false;
            }
            
            return true;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SubFormOracleConnection_Load(object sender, EventArgs e)
        {
            this.MaximizeBox = false;
            this.MinimizeBox = false;
        }

        private void btnTestConnection_Click(object sender, EventArgs e)
        {

            try
            {
                int result;
                if (!int.TryParse(textBoxOracleDBName.Text.Trim(), out result))
                {
                    //MessageBox.Show("Please enter a valid port number.", "Error: Invalid Entry");
                    MessageBox.Show("Failed", "Status");
                    return;
                }
                SHARED.Oracle o = new SHARED.Oracle(textBoxOracleServerName.Text, int.Parse(textBoxOracleDBName.Text), textBoxOracleServiceId.Text,
                   textBoxOracleUserId.Text, textBoxOraclePassword.Text);

                if (o.isConnected())
                {
                    MessageBox.Show("Successful", "Status");
                    return;
                }
                MessageBox.Show("Failed", "Status");
            }
            catch
            {
                throw;
            }

        }

        private void labelDbName_Click(object sender, EventArgs e)
        {

        }

        private void textBoxOracleDBName_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
